package d2;

import java.util.*;

public class Day5 {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5};
        PriorityQueue<Integer> pq = new PriorityQueue<>((a,b)->{
            return b-a;
        });
        pq.add(1);
        pq.add(2);
        pq.add(3);
        pq.add(4);


        //lastStoneWeight(arr);
    }
    public static int lastStoneWeight(int[] stones) {
        PriorityQueue<Integer> pq = new PriorityQueue<>((a,b)->{
            return b-a;
        });
        for(int x:stones) pq.add(x);
        while (pq.size()>1) {
            int x = pq.poll();
            int y = pq.poll();
            if(x==y) continue;
            else pq.add(y-x);
        }
        if(pq.size()==0) return 0;
        return pq.poll();
    }
}
